import { useLocation, Navigate } from 'react-router-dom'
import { menuItemType } from '@/store/reducers/login'
const poverArr = [] as menuItemType[]
export default function routerBefore({ children }: any) {
  const location = useLocation()
  const pathnameArr = location?.pathname.slice(1)
  const routeList = [
    {
      url: '../pages/ProductCenter/index.tsx',
      path: 'productcenter',
      name: '产品中心',
    },
    {
      url: '../pages/ProductCenter/add.tsx',
      path: 'productcenter/add',
      name: '产品中心新建',
    },
    {
      url: '../pages/ProductCenter/detail.tsx',
      path: 'productcenter/detail',
      name: '产品中心详情',
    },
    {
      url: '../pages/DeviceCenter/index.tsx',
      path: 'devicecenter',
      name: '设备中心',
    },
    {
      url: '../pages/DeviceCenter/detail.tsx',
      path: 'devicecenter/detail',
      name: '设备中心详情',
    },
    {
      url: '../pages/ProductType/index.tsx',
      path: 'producttype',
      name: '产品类型',
    },
    {
      url: '../pages/RegisterRecord/index.tsx',
      path: 'registerrecord',
      name: '注册记录',
    },
    {
      url: '../pages/GrantRecord/index.tsx',
      path: 'grantrecord',
      name: '路由管理中心',
    },
    {
      url: '../pages/RecoveryRecord/index.tsx',
      path: 'recoveryrecord',
      name: '应用管理',
    },
  ]
  const handleMenuList = (menuList: any[]) => {
    return menuList.map((item) => {
      if (item.children && item.children.length > 0) {
        handleMenuList(item.children)
      } else {
        if (item.path && pathnameArr === item.path) {
          poverArr.push(item)
        }
      }
    })
  }
  poverArr.length = 0
  handleMenuList(routeList || [])
  // if (poverArr.length === 0 && routeList.length !== 0) {
  //   return <Navigate to={'/403'} replace></Navigate>
  // } else {
  //   return <>{children}</>
  // }
  return <>{children}</>
}
